﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LabaCS4
{
    public partial class Add : Form
    {
        Bitmap AddFormImage = null;

        public Add()
        {
            InitializeComponent();
            button1.DialogResult = DialogResult.OK;
        }
        public void fillBook(Book cbook)
        {
            String cs;
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                cs = listBox1.Items[i].ToString();
                cbook.AddChapter(new Chapter(cs));

            }

        }
        public void GetChapterFromBook(Book cbook)
        {
            listBox1.Items.Clear();
            foreach (Chapter cg in cbook)
            {
                listBox1.Items.Add(cg.chapters);

            }


        } 

        public String Title
        {
            get { return название.Text; }
            set { название.Text = value; }
        }
        public String Author
        {
            get { return (автор.Text); }
            set { автор.Text = value; }
        }


        public String Cost
        {
            get { return (стоимость.Text); }
            set { стоимость.Text = value; }
        }
        public Bitmap Photo
        {
            get
            {
                return AddFormImage;
            }
            set
            {
                AddFormImage = value;
                pictureBox1.Image = AddFormImage;

            }

        }

        private void Add_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void название_TextChanged(object sender, EventArgs e)
        {

        }

        private void автор_TextChanged(object sender, EventArgs e)
        {

        }

        private void стоимость_TextChanged(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Image files (*.jpg)|*.jpg";
            openFileDialog.InitialDirectory = "C:\\";
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.IO.FileStream fs = new System.IO.FileStream(openFileDialog.FileName, System.IO.FileMode.Open);
                Photo = new Bitmap(Image.FromStream(fs));
                fs.Close();
                pictureBox1.Image = Photo;
            }

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(textBox1.Text);
            textBox1.Text = "";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            int cIndex = listBox1.SelectedIndex;
            if (cIndex >= 0)
            {
                listBox1.Items[cIndex] = textBox1.Text.ToString();

                //listBox1.Items.Insert(cIndex, textBox1.ToString());
                //listBox1.Items.RemoveAt(cIndex + 1);


            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int cIndex = listBox1.SelectedIndex;
            if (cIndex >= 0)
            {
                textBox1.Text = listBox1.Items[cIndex].ToString();


            }

        }
    }
}
